package com.bobo.gmall.realtime.utils;

import com.alibaba.fastjson.JSONObject;
import com.bobo.gmall.realtime.common.GmallConfig;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

public class DimUtil {

    public static JSONObject getDimInfo(Connection connection, String tableName, int id) throws Exception {
        String targetDB = "gmall_flink";
        String querySql = "select * from "+ targetDB+"."+tableName+" where id = "+id;
        List<JSONObject> queryList = JdbcUtil.queryList(connection, querySql, JSONObject.class, false);
        return queryList.get(0);

    }

    public static JSONObject getDimInfo(Connection connection, String tableName, String id) throws Exception {
        String targetDB = "gmall_flink";
        String querySql = "select * from "+ targetDB+"."+tableName+" where id = '"+id+"'";
        List<JSONObject> queryList = JdbcUtil.queryList(connection, querySql, JSONObject.class, false);
        return queryList.get(0);

    }


    public static void main(String[] args) throws Exception {

        Class.forName(GmallConfig.MYSQL_DRIVER);
        Connection connection = DriverManager.getConnection(GmallConfig.MYSQL_SERVER);

        long start = System.currentTimeMillis();
        System.out.println(getDimInfo(connection,"base_region","1"));
        long end = System.currentTimeMillis();
        System.out.println(getDimInfo(connection,"base_region","1"));
        long end2 = System.currentTimeMillis();

        System.out.println(end-start);
        System.out.println(end2-end);

        connection.close();

    }

}
